// 处理音乐时长

import axios from 'axios';

export function formattingTime(list) {
    for (let i = 0; i < list.length; i++) {
        // 总毫秒数
        let duration = list[i].duration;
        list[i].duration = formattingTimeBefore(duration);
    }
    return list;
}

export function formattingTimeBefore(duration) {
    let min = Math.floor(duration / 1000 / 60);
    let sec = Math.floor((duration / 1000) % 60);
    min = min >= 10 ? min : "0" + min;
    sec = sec >= 10 ? sec : "0" + sec;
    return `${min}:${sec}`
}


export function formattingPlaycount(list) {
    for (let i = 0; i < list.length; i++) {
        let playCount = list[i].playCount;
        let num = Math.floor(playCount / 1000);
        if (num > 0) {
            if (num >= 10) {
                num = Math.floor(num / 10);
                list[i].playCount = `${num}w+`;
            } else {
                list[i].playCount = `${num}k+`;
            }
        }
    }
    return list;
}